<?php
declare (strict_types = 1);

namespace app\adminapi\controller\organize;

use adminmatrix\admin\BaseController;
use adminmatrix\admin\service\JsonService;
use app\adminapi\logic\organize\AdminDepartmentLogic;
use think\Request;
use think\response\Json;
use hg\apidoc\annotation as Apidoc;
#[
    Apidoc\Title("部门列表"),
    Apidoc\Group("organize")
]
class DepartmentController extends BaseController
{

    #[
        Apidoc\Title("获取部门列表"),
        Apidoc\Tag("部门列表")
    ]
   public function lists() : Json
   {
       return  $this->dataLists();
   }

   #[
        Apidoc\Title("新增部门"),
        Apidoc\Method("POST"),
        Apidoc\Author("Xiaobin"),
        Apidoc\Tag("部门列表")
   ]
   public function save(Request $request , AdminDepartmentLogic $departmentLogic)  : Json
   {
       try {
           $departmentLogic->save($request);
           return  JsonService::success("新增部门成功");
       } catch (\Exception $exception)
       {
           return JsonService::fail($exception->getMessage());
       }
   }

   #[
        Apidoc\Title("修改部门"),
        Apidoc\Method("PUT"),
        Apidoc\Author("Xiaobin"),
        Apidoc\Tag("部门列表")
   ]
   public function update(Request $request , AdminDepartmentLogic $logic): Json
   {
       try {
           $logic -> update($request);
           return  JsonService::success("修改部门成功");
       } catch (\Exception $exception)
       {
           return  JsonService::fail($exception->getMessage());
       }
   }

   #[
        Apidoc\Title("删除部门"),
        Apidoc\Method("DELETE"),
        Apidoc\Author("Xiaobin"),
        Apidoc\Tag("部门列表")
   ]
   public function delete(Request $request , AdminDepartmentLogic $logic): Json
   {
       try {
           $logic->delete($request);
           return JsonService::success("删除部门成功");
       } catch (\Exception $exception)
       {
           return JsonService::fail($exception->getMessage());
       }
   }

}
